home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / MX2_VLA.ZIP / MODEX2.INC < prev    next >
Text File  |  1993-10-03  |  23KB  |  729 lines

  1. MASM
  2. COMMENT $
  3. ────────────────────────────────────────────────────────────────────────────
  4.  This library written by Draeden of VLA.
  5.  
  6.  Major thanks go to Themie Gouthas, as he is responsible for the majority
  7.  of the screen dimentions (all except 256 wide)
  8.  
  9.  
  10.  Four routines seperate this ModeX library from the others:
  11.  
  12.   ResetLinear = Puts you into Mode 13h addressing again
  13.  
  14.   ResetPlanar = And puts you back into planar mode
  15.  
  16.   Do16  = Changes to a normal 16 color mode
  17.  
  18.   Do256 = Changes back to a 256 color mode
  19.  
  20.  
  21. Use:
  22.     @SetModeX x360, y480, 1, 360    ;sets a 360x480x256 mode
  23.  
  24.   The x360 is what width to use, the y480 is how many scan lines to use,
  25.   the 0 is how many scan lines each pixel uses, and the 360 is the 
  26.   virtual width of the screen.
  27.  
  28.   So, to set a "80x50x256" mode, you'd do this:
  29.  
  30.     @SetModeX x320, y400, 4, 320
  31.  
  32.   This sets a 320 pixel wide screen with each pixel having a height of 4.
  33.  
  34.   Enjoy.
  35.  
  36. ────────────────────────────────────────────────────────────────────────────
  37. $
  38. Ideal
  39. p386
  40. ────────────────────────────────────────────────────────────────────────────
  41. SCANy350 = 10000000b    ;(362 active)
  42. SCANy400 = 01000000b    ;(414 active)
  43. SCANy480 = 11000000b    ;(496 active)
  44.  
  45. SCANx360 = 00000100b    ;(720 wide) 25-mHZ
  46. SCANx320 = 00000000b    ;(640 wide) 28-mHZ
  47. ────────────────────────────────────────────────────────────────────────────
  48. LABEL _x256 WORD
  49.     db      SCANx320    ; Clock Select (CS)
  50.     db      06          ; Number of CRTC Registers to update
  51.     dw      05f00h      ; horz total
  52.     dw      03f01h      ; horz displayed
  53.     dw      04002h      ; start horz blanking
  54.     dw      0a003h      ; end horz blanking
  55.     dw      04f04h      ; start h sync
  56.     dw      00405h      ; end h sync
  57.     
  58. LABEL _x320 WORD
  59.     db      SCANx320    ; Clock Select (CS)
  60.     db      0           ; Number of CRTC Registers to update
  61.  
  62. LABEL _x360 WORD
  63.     db      SCANx360    ; Clock Select (CS)
  64.     db      06          ; Number of CRTC Registers to update
  65.     dw      06b00h      ; horz total
  66.     dw      05901h      ; horz displayed
  67.     dw      05a02h      ; start horz blanking
  68.     dw      08e03h      ; end horz blanking
  69.     dw      05e04h      ; start h sync
  70.     dw      08a05h      ; end h sync
  71.  
  72. LABEL _x376 WORD
  73.     db      SCANx360    ; Clock Select (CS)
  74.     db      06          ; Number of CRTC Registers to update
  75.     dw      06e00h      ; horz total
  76.     dw      05d01h      ; horz displayed
  77.     dw      05e02h      ; start horz blanking
  78.     dw      09103h      ; end horz blanking
  79.     dw      06204h      ; start h sync
  80.     dw      08f05h      ; end h sync
  81. ────────────────────────────────────────────────────────────────────────────
  82. LABEL _y308 WORD
  83.     db      SCANy400    ; Horizontal Sync Polarity (HSP)
  84.     db      7           ; Number of CRTC Registers to update
  85.     dw      06206h      ; vertical total
  86.     dw      00f07h      ; overflow (VRS, VDE, VBS, VT)
  87.     dw      03710h      ; v sync start
  88.     dw      08911h      ; v sync end and protect cr0-cr7
  89.     dw      03312h      ; vertical displayed
  90.     dw      03c15h      ; v blank start
  91.     dw      05c16h      ; v blank end
  92.  
  93. LABEL _Y360 word
  94.     db      SCANy480    ; Horizontal Sync Polarity (HSP)
  95.     db      5           ; Number of CRTC Registers to update
  96.     dw      08810h      ; v sync start
  97.     dw      08511h      ; v sync end and protect cr0-cr7
  98.     dw      06712h      ; vertical displayed
  99.     dw      06d15h      ; v blank start
  100.     dw      0ba16h      ; v blank end
  101.     
  102. LABEL _y400 WORD
  103.     db      SCANy400    ; Horizontal Sync Polarity (HSP)
  104.     db      0           ; Number of CRTC Registers to update     
  105.  
  106. LABEL _y480 WORD
  107.     db      SCANy480    ; Horizontal Sync Polarity (HSP)
  108.     db      7           ; Number of CRTC Registers to update
  109.     dw      00d06h      ; vertical total
  110.     dw      03e07h      ; overflow (VRS, VDE, VBS, VT)
  111.     dw      0ea10h      ; v sync start
  112.     dw      0ac11h      ; v sync end and protect cr0-cr7
  113.     dw      0df12h      ; vertical displayed
  114.     dw      0e715h      ; v blank start
  115.     dw      00616h      ; v blank end
  116.     
  117. LABEL _y564 WORD
  118.     db      SCANy480    ; Horizontal Sync Polarity (HSP)
  119.     db      8           ; Number of CRTC Registers to update
  120.     dw      06206h      ; vertical total
  121.     dw      0f007h      ; overflow (VRS, VDE, VBS, VT)
  122.     dw      06009h      ; set VBS bit 9
  123.     dw      03710h      ; v sync start
  124.     dw      08911h      ; v sync end and protect cr0-cr7
  125.     dw      03312h      ; vertical displayed
  126.     dw      03c15h      ; v blank start
  127.     dw      05c16h      ; v blank end
  128. ────────────────────────────────────────────────────────────────────────────
  129. x256    =   0
  130. x320    =   1
  131. x360    =   2
  132. x376    =   3
  133.  
  134. y308    =   0
  135. y360    =   1
  136. y400    =   2
  137. y480    =   3
  138. y564    =   4
  139.  
  140. o EQU OFFSET
  141. s EQU SHORT
  142.  
  143. Xmodes  dw  o _x256, o _x320, o _x360, o _x376
  144. Ymodes  dw  o _y308, o _y360, o _y400, o _y480, o _y564
  145.  
  146. NumXmodes   =   4
  147. NumYmodes   =   5
  148. ────────────────────────────────────────────────────────────────────────────
  149. InputStatus1=   3dah
  150. MISC_OUTPUT =   3c2h
  151. READ_MISC   =   3cch
  152. SC_Index    =   3c4h
  153. CRTC_Index  =   3d4h
  154. Graph_Index =   3ceh
  155. Attr_Index  =   3c0h    ;don't forget to clear flipflop & set bit 5 on index
  156. PEL_Write   =   3c8h
  157. PEL_Read    =   3c7h
  158. PEL_Data    =   3c9h
  159.  
  160. VGASeg      dw  0a000h
  161. ────────────────────────────────────────────────────────────────────────────
  162.     ────────────────────────────────────────────────────────────────────
  163.     ; A MACRO!
  164.     ;
  165.     ; ARG: Xmode:Byte, Ymode:Byte, Cell_Height:Byte, Virtual_Width:WORD
  166.     ;
  167.     ; CELL_HEIGHT: how tall each pixel is in scan lines
  168.     ;
  169.     ────────────────────────────────────────────────────────────────────
  170. MACRO @SetModeX DaXmode, DaYmode, CHeight, DaWidth
  171.     mov     al,DaXmode
  172.     mov     ah,DaYmode
  173.     call    _Set_X_Mode
  174.     mov     ax,DaWidth
  175.     call    Set_Width
  176.     mov     ah,CHeight
  177.     call    Set_CellHeight
  178. ENDM @SetModeX
  179.     ────────────────────────────────────────────────────────────────────
  180.     ; Set a planar mode with requested dimensions
  181.     ;
  182.     ; IN: AL = index into X res chart
  183.     ;     AH = index into Y res chart
  184.     ;
  185.     ;OUT: CF = 1, invalid mode
  186.     ;     CF = 0, success
  187.     ────────────────────────────────────────────────────────────────────
  188. PROC _Set_X_Mode NEAR
  189.  
  190.     cmp     ah,NumYmodes
  191.     jae     s @@InvalidMode
  192.     cmp     al,NumYmodes
  193.     jae     s @@InvalidMode
  194.  
  195.     jmp     s @@ValidMode
  196.  
  197. @@InvalidMode:
  198.     stc                         ; idiot.
  199.     ret
  200.  
  201. @@ValidMode:
  202.     pusha
  203.     push    es ds
  204.  
  205.     cld
  206.     mov     bx,cs
  207.     mov     ds,bx
  208.     mov     es,bx
  209.  
  210.     movzx   si,al
  211.     add     si,si
  212.     mov     si,[si + Xmodes]    ; point to correct X data set
  213.     movzx   bx,ah
  214.     add     bx,bx
  215.     mov     bx,[bx + Ymodes]    ; point to correct Y data set
  216.  
  217.     mov     ax,13h              ; let the BIOS set standard 256-color
  218.     int     10h                 ;  mode (320x200 linear)
  219.  
  220.     mov     dx,SC_INDEX
  221.     mov     ax,0604h
  222.     out     dx,ax               ; disable chain4 mode
  223.  
  224.     mov     ch,[si]             ; get X clock
  225.     or      ch,[bx]             ; get Y clock
  226.     or      ch,00100011b        ; set PB, ER, IOA
  227.     inc     si
  228.     inc     bx
  229.     
  230.     mov     dx,READ_MISC
  231.     in      al,dx
  232.     cmp     al,ch
  233.     je      s @@NoClockSet
  234.  
  235.     mov     dx,SC_INDEX
  236.     mov     ax,0100h
  237.     out     dx,ax               ; synchronous reset while setting Misc Output
  238.     
  239.     mov     dx,MISC_OUTPUT
  240.     mov     al,ch
  241.     out     dx,al               ; select the dot clock and Horiz
  242.                                 ;  scanning rate
  243.     mov     dx,SC_INDEX
  244.     mov     ax,0300h
  245.     out     dx,ax               ; undo reset (restart sequencer)
  246.  
  247. @@NoClockSet:
  248.  
  249.     mov     dx,CRTC_INDEX       ; reprogram the CRT Controller
  250.     mov     al,11h              ; VSync End reg contains register write
  251.     out     dx,al               ; protect bit
  252.     inc     dx                  ; CRT Controller Data register
  253.     in      al,dx               ; get current VSync End register setting
  254.     and     al,07fh             ; remove write protect on various
  255.     out     dx,al               ; CRTC registers
  256.     dec     dx                  ; CRT Controller Index
  257.  
  258.     mov     ax,00014h           ; turn off dword mode
  259.     out     dx,ax
  260.     mov     ax,0e317h           ; turn on byte mode
  261.     out     dx,ax
  262.  
  263.     lodsb                       ; lets do the X stuff
  264.     movzx   cx,al
  265.     jcxz    @@NoX
  266.  
  267. @@SetCRTParmsLoop:
  268.     lodsw                       ; do the next CRT Index/Data pair
  269.     out     dx,ax
  270.     loop    @@SetCRTParmsLoop
  271.  
  272. @@NoX:
  273.     mov     si,bx
  274.     lodsb
  275.     movzx   cx,al
  276.     jcxz    @@NoY
  277.  
  278. @@SetCRTParmsLoop2:
  279.     lodsw                       ; do the next CRT Index/Data pair
  280.     out     dx,ax
  281.     loop    @@SetCRTParmsLoop2
  282.  
  283. @@NoY:
  284.  
  285.     mov     dx,SC_INDEX
  286.     mov     ax,0f02h
  287.     out     dx,ax               ; enable writes to all four planes
  288.  
  289.                                 ; now clear all display memory, 8 pixels
  290.     mov     es,[VGAseg]         ; at a time
  291.     xor     di,di               ; point ES:DI to display memory
  292.     xor     ax,ax               ; clear to zero-value pixels
  293.     mov     cx,8000h            ; # of words in display memory
  294.     rep     stosw               ; clear all of display memory
  295.     
  296.     pop     ds es
  297.     popa
  298.     clc                         ; success!
  299.     ret
  300. ENDP
  301. ────────────────────────────────────────────────────────────────────────────
  302. ;*   MISC planar mode routines
  303. ────────────────────────────────────────────────────────────────────────────
  304.     ────────────────────────────────────────────────────────────────────
  305.     ; Sets logical width of screen to whats in CX
  306.     ────
  307.     ; IN: AX = desired width
  308.     ;
  309.     ;OUT: AX = real width
  310.     ────────────────────────────────────────────────────────────────────
  311. PROC Set_Width NEAR
  312.     push    dx
  313.     shr     ax,3            ; divide by 8
  314.     mov     ah,al           ; move value into AH
  315.     mov     dx,CRTC_INDEX   ; get the PORT
  316.     mov     al,13h          ; and the INDEX
  317.     out     dx,ax           ; set it
  318.     movzx   ax,ah           ; put value back in AX
  319.     shl     ax,3            ; mult by 8
  320.     pop     dx
  321.     ret
  322. ENDP
  323.     ────────────────────────────────────────────────────────────────────
  324.     ; Sets the MSL register.  It's the number of scan lines the
  325.     ; data is repeated before advancing to the next data line. 
  326.     ; (Char Height in TEXT mode.)
  327.     ────
  328.     ; IN: AH = Cell height
  329.     ;
  330.     ;OUT: AX is destoryed
  331.     ────────────────────────────────────────────────────────────────────
  332. PROC Set_CellHeight NEAR
  333.     push    dx
  334.     dec     ah              ;Cell height - 1
  335.     mov     dx,CRTC_Index
  336.     mov     al,9
  337.     out     dx,al
  338.     inc     dl
  339.     in      al,dx
  340.     and     al,11100000b
  341.     or      al,ah
  342.     out     dx,al
  343.     pop     dx
  344.     ret
  345. ENDP
  346.     ────────────────────────────────────────────────────────────────────
  347.     ; Latches the planes to be read from/written to
  348.     ;
  349.     ; NOTE: After calling this routine once, you can set the latch by
  350.     ;       doing an OUT to PORT SC_Index + 1 with the plane mask.
  351.     ;       This works until SC_Index is changed.
  352.     ────
  353.     ; IN: AH = plane mask - bit 0 = plane 0, 1 = 1, etc.. upto 4
  354.     ;
  355.     ;OUT: AL is destroyed
  356.     ────────────────────────────────────────────────────────────────────
  357. PROC Latch_Planes NEAR
  358.     push    dx
  359.     mov     dx,SC_Index
  360.     mov     al,2
  361.     out     dx,ax
  362.     pop     dx
  363.     ret
  364. ENDP
  365.     ────────────────────────────────────────────────────────────────────
  366.     ; Latches a plane for READ operation (only for READ MODE #0)
  367.     ────
  368.     ; IN: AH = plane to latch for read (0-3)
  369.     ;
  370.     ;OUT: AL is destroyed
  371.     ────────────────────────────────────────────────────────────────────
  372. PROC  Set_Read_Plane NEAR
  373.     push    dx
  374.     mov     dx,Graph_Index
  375.     mov     al,4
  376.     out     dx,ax
  377.     pop     dx
  378.     ret
  379. ENDP
  380.     ────────────────────────────────────────────────────────────────────
  381.     ; Sets WRITE mode (0-3)
  382.     ;
  383.     ; WM0:  Data from BUS goes to Video Memory (all latched planes)
  384.     ;
  385.     ; WM1:  Data is read into 32bit latch and written from 32bit latch
  386.     ;       BUS data has no effect.  Allows data from all 4 planes to 
  387.     ;       be moved from one place in VGA to another.
  388.     ;
  389.     ; WM2 & WM3:  Look them up.
  390.     ;
  391.     ────
  392.     ; IN: AH = WRITE mode (0-3)
  393.     ;
  394.     ;OUT: AL is destroyed
  395.     ────────────────────────────────────────────────────────────────────
  396. PROC Set_Write_Mode NEAR
  397.     push    dx
  398.     mov     dx,Graph_Index
  399.     mov     al,5
  400.     out     dx,al
  401.     inc     dx
  402.     in      al,dx
  403.     and     al,11111100b    ;clear out write mode bits
  404.     or      al,ah
  405.     out     dx,al
  406.     pop     dx
  407.     ret
  408. ENDP
  409.     ────────────────────────────────────────────────────────────────────
  410.     ; Sets the READ mode
  411.     ;
  412.     ; RM0 = Normal one. Reads data.
  413.     ;
  414.     ; RM1 = Weird one. Reads results of comparison.
  415.     ────
  416.     ; IN: AH = read mode (0 or 1)
  417.     ;
  418.     ;OUT: AX is destroyed
  419.     ────────────────────────────────────────────────────────────────────
  420. PROC Set_Read_Mode NEAR
  421.     push    dx
  422.     mov     dx,Graph_Index
  423.     mov     al,5
  424.     out     dx,al
  425.     inc     dx
  426.     in      al,dx
  427.     and     al,11110111b    ;clear out write mode bits
  428.     shl     ah,3            ;move bit to correct position
  429.     and     ah,00001000b
  430.     or      al,ah
  431.     out     dx,al
  432.     pop     dx
  433.     ret
  434. ENDP
  435.     ────────────────────────────────────────────────────────────────────
  436.     ; Sets starting offset - useful for panning or using multiple pages.
  437.     ;
  438.     ────
  439.     ; IN: BX = Offset
  440.     ;
  441.     ;OUT: AX is destoryed
  442.     ────────────────────────────────────────────────────────────────────
  443. PROC Set_Start_Offset NEAR
  444.     push    dx
  445.     mov     dx,CRTC_Index
  446.     mov     al,0ch
  447.     mov     ah,bh       ;write the HIGH byte
  448.     out     dx,ax
  449.     inc     al
  450.     mov     ah,bl       ;write the LOW byte
  451.     out     dx,ax
  452.     pop     dx
  453.     ret
  454. ENDP
  455.     ────────────────────────────────────────────────────────────────────
  456.     ; Sets the pelpan value - useful for smooth sideways panning
  457.     ;
  458.     ; NOTE: DO NOT USE ODD VALUES except in text mode or 16 color mode
  459.     ;
  460.     ────
  461.     ; IN: AH = pelpan value
  462.     ;
  463.     ;OUT: AL is destoryed
  464.     ────────────────────────────────────────────────────────────────────
  465. PROC Set_HPP NEAR
  466.     push    dx
  467.     mov     dx,InputStatus1
  468.     in      al,dx           ;dummy input
  469.     mov     dx,Attr_Index
  470.     mov     al,33h
  471.     out     dx,al
  472.     mov     al,ah
  473.     out     dx,al
  474.     pop     dx
  475.     ret
  476. ENDP
  477.     ────────────────────────────────────────────────────────────────────
  478.     ; Sets pixel pan compatibility - makes it so the HPP value does not
  479.     ;  alter the split screen.
  480.     ────────────────────────────────────────────────────────────────────
  481. PROC Set_PPC NEAR
  482.     push    ax dx
  483.     mov     dx,InputStatus1
  484.     in      al,dx           ;dummy input
  485.     mov     dx,Attr_Index
  486.     mov     al,30h
  487.     out     dx,al
  488.     inc     dx
  489.     in      al,dx
  490.     dec     dx
  491.     or      al,00100000b
  492.     out     dx,al
  493.     pop     dx ax
  494.     ret
  495. ENDP
  496.     ────────────────────────────────────────────────────────────────────
  497.     ; Sets the split screen scan line
  498.     ────
  499.     ; IN: BX = Scan line to set split at
  500.     ;
  501.     ;OUT: None
  502.     ────────────────────────────────────────────────────────────────────
  503. PROC Set_Split NEAR
  504.     push    dx ax
  505.     mov     al,18h
  506.     mov     ah,bl
  507.     mov     dx,CRTC_Index
  508.     out     dx,ax       ;set bits 0-7
  509.  
  510.     mov     al,09h
  511.     out     dx,al
  512.     inc     dx
  513.     in      al,dx
  514.     mov     ah,bh
  515.     and     ah,00000010b
  516.     shl     ah,5
  517.     and     al,10111111b
  518.     or      al,ah
  519.     out     dx,al       ;set bit 9
  520.  
  521.     dec     dx
  522.     mov     al,07h
  523.     out     dx,al
  524.     inc     dx
  525.     in      al,dx
  526.     and     al,11101111b
  527.     mov     ah,bh
  528.     and     ah,00000001b
  529.     shl     ah,4
  530.     or      al,ah
  531.     out     dx,al       ;set bit 8
  532.     pop     ax dx
  533.     ret
  534. ENDP
  535.     ────────────────────────────────────────────────────────────────────
  536.     ; Waits until verticle retrace starts and then waits for it to end.
  537.     ────────────────────────────────────────────────────────────────────
  538. PROC Wait_FVR1 NEAR
  539.     push    dx ax
  540.     mov     dx,InputStatus1
  541. @@Vr:
  542.     in      al,dx
  543.     test    al,8
  544.     jz      s @@Vr                  ;wait until Verticle Retrace starts
  545. @@Nvr:
  546.     in      al,dx
  547.     test    al,8
  548.     jnz     s @@Nvr                 ;wait until Verticle Retrace Ends
  549.     pop     ax dx
  550.     ret
  551. ENDP
  552.     ────────────────────────────────────────────────────────────────────
  553.     ; Waits until NON-VR time and then wait for VR to start
  554.     ────────────────────────────────────────────────────────────────────
  555. PROC Wait_FVR2 NEAR
  556.     push    dx ax
  557.     mov     dx,InputStatus1
  558. @@Vr:
  559.     in      al,dx
  560.     test    al,8
  561.     jnz     s @@Vr                  ;wait until Verticle Retrace starts
  562. @@Nvr:
  563.     in      al,dx
  564.     test    al,8
  565.     jz      s @@Nvr                 ;wait until Verticle Retrace Ends
  566.     pop     ax dx
  567.     ret
  568. ENDP
  569.     ────────────────────────────────────────────────────────────────────
  570.     ; Waits until VR is true - MAY be missed if interrupts are enabled
  571.     ────────────────────────────────────────────────────────────────────
  572. PROC Wait_VR NEAR
  573.     push    dx ax
  574.     mov     dx,InputStatus1
  575. @@Vr:
  576.     in      al,dx
  577.     test    al,8
  578.     jz      s @@Vr                  ;wait until Verticle Retrace starts
  579.     pop     ax dx
  580.     ret
  581. ENDP
  582.     ────────────────────────────────────────────────────────────────────
  583.     ; Waits for a NON-VR period
  584.     ────────────────────────────────────────────────────────────────────
  585. PROC Wait_NVR NEAR
  586.     push    dx ax
  587.     mov     dx,InputStatus1
  588. @@Nvr:
  589.     in      al,dx
  590.     test    al,8
  591.     jnz     s @@Nvr                 ;wait until Verticle Retrace Ends
  592.     pop     ax dx
  593.     ret
  594. ENDP
  595.     ────────────────────────────────────────────────────────────────────
  596.     ; Write a specified palette chunk
  597.     ────
  598.     ; IN: DS:SI = Address of palette
  599.     ;        CX = Number of colors to write (NOT *3)
  600.     ;        AL = Starting palette index
  601.     ;
  602.     ;OUT: None
  603.     ────────────────────────────────────────────────────────────────────
  604. PROC WritePalette NEAR
  605.     push    dx cx si
  606.     mov     dx,cx
  607.     add     cx,cx
  608.     add     cx,dx
  609.     mov     dx,03c8h
  610.     out     dx,al
  611.     inc     dx
  612.     cld
  613.     rep outsb
  614.     pop     si cx dx
  615.     ret
  616. ENDP
  617.     ────────────────────────────────────────────────────────────────────
  618.     ; Puts the VGA card back into PLANAR mode at current resolutions
  619.     ;
  620.     ; NOTE: It is recommended that you clear ALL 256k VGA memory AFTER
  621.     ;       resetting into PLANAR mode, as SOME VGA cards may go funky.
  622.     ────────────────────────────────────────────────────────────────────
  623. PROC ResetPlanar NEAR
  624.     push    ax dx
  625.     mov     dx,SC_INDEX
  626.     mov     ax,0604h
  627.     out     dx,ax               ; disable chain4 mode
  628.     
  629.     mov     dx,CRTC_INDEX
  630.     mov     ax,00014h           ; turn off dword mode
  631.     out     dx,ax
  632.     mov     ax,0e317h           ; turn on byte mode
  633.     out     dx,ax
  634.     pop     dx ax
  635.     ret
  636. ENDP
  637.     ────────────────────────────────────────────────────────────────────
  638.     ; Changes from ModeX back to linear mode (like MODE 13h)
  639.     ;
  640.     ; NOTE: It is recommended that you clear ALL 256k VGA memory BEFORE
  641.     ;       resetting into LINEAR mode, as SOME VGA cards may go funky.
  642.     ────────────────────────────────────────────────────────────────────
  643. PROC ResetLinear NEAR
  644.     push    dx ax
  645.     mov     dx,SC_INDEX
  646.     mov     ax,0E04h
  647.     out     dx,ax               ; enable chain4 mode
  648.  
  649.     mov     dx,CRTC_INDEX       ; reprogram the CRT Controller
  650.     mov     ax,04014h           ; turn on dword mode
  651.     out     dx,ax
  652.     mov     ax,0a317h           ; turn off byte mode
  653.     out     dx,ax
  654.     pop     ax dx
  655.     ret
  656. ENDP
  657. ────────────────────────────────────────────────────────────────────────────
  658. ;Differences between 16 color mode and X-Mode:
  659. ;
  660. ;        16 color     256 color
  661. ;
  662. ; GRAPH  5 = 00h        40h     ;Shift register is different
  663. ;
  664. ; ATTR   6 = 14h        06      ;these are palette remap differences
  665. ;        8 = 38h        08      ; so they don't matter one whit
  666. ;        9 = 39h        09
  667. ;        A = 3ah        0a
  668. ;        B = 3bh        0b
  669. ;        C = 3ch        0c
  670. ;        D = 3dh        0d
  671. ;        E = 3eh        0e
  672. ;        F = 3fh        0f
  673. ;       10 = 01h        41      ;PCS is different
  674. ────────────────────────────────────────────────────────────────────────────
  675.     ────────────────────────────────────────────────────────────────────
  676.     ;   Changes FROM 256 color planar TO 16 color planar
  677.     ;
  678.     ; The screen WILL screw up when the change is made, so clear it
  679.     ;first.  Also sets the read/write mode to 0.
  680.     ────────────────────────────────────────────────────────────────────
  681. PROC Do16 NEAR
  682.     push    ax dx
  683.  
  684.     mov     dx,Graph_Index
  685.     mov     ax,00005h           ;set Shift reg to 0
  686.     out     dx,ax
  687.  
  688.     mov     dx,InputStatus1
  689.     in      al,dx               ;dummy input
  690.     mov     dx,Attr_Index
  691.     mov     al,30h
  692.     out     dx,al
  693.     mov     al,21h              ;turn off PCS, and turns on PCC
  694.     out     dx,al
  695.  
  696.     mov     ah,0
  697.     call    Set_Hpp
  698.  
  699.     pop     dx ax
  700.     ret
  701. ENDP
  702.     ────────────────────────────────────────────────────────────────────
  703.     ;   Changes FROM 16 color planar TO 256 color planar
  704.     ;
  705.     ; The screen WILL screw up when the change is made, so clear it
  706.     ;first.  Also sets the read/write mode to 0.
  707.     ────────────────────────────────────────────────────────────────────
  708. PROC Do256 NEAR
  709.     push    ax dx
  710.  
  711.     mov     dx,Graph_Index
  712.     mov     ax,04005h           ;set Shift reg to 1
  713.     out     dx,ax
  714.  
  715.     mov     dx,InputStatus1
  716.     in      al,dx               ;dummy input
  717.     mov     dx,Attr_Index
  718.     mov     al,30h
  719.     out     dx,al
  720.     mov     al,61h              ;turns on PCS & PCC
  721.     out     dx,al
  722.  
  723.     mov     ah,0
  724.     call    Set_Hpp
  725.  
  726.     pop     dx ax
  727.     ret
  728. ENDP
  729.